package com.intermancer.predictor.gene.logic;

import java.util.List;

import com.intermancer.predictor.data.Channel;
import com.intermancer.predictor.data.ConsumeResponse;
import com.intermancer.predictor.data.Quantum;
import com.intermancer.predictor.mutation.MutationAssistant;
import com.intermancer.predictor.mutation.MutationCommand;
import com.intermancer.predictor.mutation.MutationContext;

public class SingleChannelSwitchLG extends AbstractLogicGene {
	
	public class ThresholdMC implements MutationCommand {

		public void execute(MutationAssistant mutationAssistant,
				MutationContext context) {
			threshold = mutationAssistant.adjustDouble(threshold, context);
		}

	}

	public static final double DEFAULT_THRESHOLD = 0.0;
	
	private double threshold = DEFAULT_THRESHOLD;

	@Override
	public int getOffsetsSize() {
		return 3;
	}

	@Override
	public ConsumeResponse consumeInternal(Quantum quantum) {
		if(compare(getValues()[0], threshold)) {
			quantum.addChannel(new Channel(this, getValues()[1]));
		} else {
			quantum.addChannel(new Channel(this, getValues()[2]));
		}
		return ConsumeResponse.CONSUME_COMPLETE;
	}

	@Override
	public List<MutationCommand> assembleMutationCommandList() {
		List<MutationCommand> commands = super.assembleMutationCommandList();
		commands.add(new ThresholdMC());
		return commands;
	}

	public double getThreshold() {
		return threshold;
	}

	public void setThreshold(double threshold) {
		this.threshold = threshold;
	}

}
